/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.accounting.web;

import java.util.List;

import com.javaeye.accounting.dto.MaterialsMonthChangeDetail;
import com.javaeye.accounting.service.IMaterialsMonthChangeDetailService;
import com.javaeye.common.util.DateUtils;
import com.javaeye.store.dto.Materials;
import com.javaeye.store.service.IMaterialsService;
import com.opensymphony.xwork2.ActionSupport;

public class MaterialsMonthChangeDetailAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -197381205794811886L;
	
	public static final int STROE_TYPE_NORMAL = 0;
	
	public static final int STROE_TYPE_DEFECTIVE = 1;
	
	
	/**
	 * 用于接受查询画面上选择日期的值
	 */
	private String queryDate;
	
	private int materialsId;
	
	private int skuDetailId;
	
	/**
	 * 库存区分 0:合格库存 1:不合格库存
	 */
	private int queryType;
	
	/**
	 * 查询结果列表
	 */
	private List<MaterialsMonthChangeDetail> changeDetails;
	
	private Materials materials;
	
	private IMaterialsService materialsService;
	
	private IMaterialsMonthChangeDetailService service;
	

	public MaterialsMonthChangeDetailAction() {
		queryDate = DateUtils.dateToString("yyyy-MM");
		queryType = STROE_TYPE_NORMAL;
		materialsId = -1;
		skuDetailId = -1;
	}
	
	public void setMaterialsService(IMaterialsService materialsService) {
		this.materialsService = materialsService;
	}

	public void setService(IMaterialsMonthChangeDetailService service) {
		this.service = service;
	}

	public String queryMaterialsMonthChangeDetail() throws Exception {
		if (materialsId > 0) {
			materials = materialsService.getMaterials(String.valueOf(materialsId));
			if (queryType == STROE_TYPE_NORMAL) {
				changeDetails = service.queryMaterialsMonthChangeDetail(queryDate, skuDetailId);
			} else {
				changeDetails = service.queryMaterialsDefectiveMonthChangeDetail(queryDate, skuDetailId);
			}
		}
		return SUCCESS;
	}

	public String getQueryDate() {
		return queryDate;
	}

	public void setQueryDate(String queryDate) {
		this.queryDate = queryDate;
	}

	public int getMaterialsId() {
		return materialsId;
	}

	public void setMaterialsId(int materialsId) {
		this.materialsId = materialsId;
	}

	public List<MaterialsMonthChangeDetail> getChangeDetails() {
		return changeDetails;
	}

	public void setChangeDetails(List<MaterialsMonthChangeDetail> changeDetails) {
		this.changeDetails = changeDetails;
	}

	public int getSkuDetailId() {
		return skuDetailId;
	}

	public void setSkuDetailId(int skuDetailId) {
		this.skuDetailId = skuDetailId;
	}

	public Materials getMaterials() {
		return materials;
	}

	public void setMaterials(Materials materials) {
		this.materials = materials;
	}

	public void setQueryType(int queryType) {
		this.queryType = queryType;
	}

	public int getQueryType() {
		return queryType;
	}

}
